#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
vector<long long> s, s1, e, e1;
void sort(int left, int right);
bool cmp(int wl, int hl, int i);
priority_queue<long long> q;
long long ee = 1e+9 + 7;


int main()
{
    int n(0), k(0);
    cin >> n >> k;
    for(int i = 0; i < n; i++) 
    {
        int tmp1(0);
        cin >> tmp1;
        s.push_back(tmp1);
        // s1.push_back(tmp1);
    }
    for(int i = 0; i < n; i++) 
    {
        int tmp2(0);
        cin >> tmp2;
        e.push_back(tmp2);
        // e1.push_back(tmp2);
    }
    int len = e.size();
    sort(0, len-1);
    // for(int i = 0; i < e.size(); i++) cout << e[i] << " ";
    // cout << endl;
    long long sum = 0;
    long long ans = 0;
    for(int i = 0; i < len; i++)
    {
        sum += s[i];
        q.push(-s[i]);  // 
        while(q.size() > k)
        {
            sum += q.top();
            q.pop();
        }
        ans = max(ans, sum*e[i]);
        
    }
    // cout << ee << endl;
    cout << ans%ee;
    return 0;
}


void sort(int left, int right)
{
if(left >= right) return;

int i = left;
int j = right;
int wl = s[left];
int hl = e[left];
while(i < j)
{
    // cout << i << " " << j << " " << left << endl;
    while(i < j && cmp(wl, hl, j)) j--;
    s[i] = s[j];
    e[i] = e[j];

    while(i < j && !cmp(wl, hl, i)) i++;
    s[j] = s[i];
    e[j] = e[i];
}
// cout << 1 << endl;
s[i] = wl;
e[i] = hl;
sort(left, i-1);
sort(i+1, right);
}
bool cmp(int wl, int hl, int i)
{
    // if(wl < w[i]) return true;
    // if(wl > w[i]) return false;
    if(hl > e[i]) return true;
    else return false;
}